package com.tanhua.dubbo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.domain.db.Option;
import com.tanhua.domain.db.SoulQuestion;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 范旭升
 * @create 2021/8/23
 */

public interface SoulQuestionMapper extends BaseMapper<SoulQuestion> {


    @Select("SELECT id,question,questionnaire_id AS questionnaireId FROM tb_bquestion WHERE questionnaire_id = #{questionId} ")
    List<SoulQuestion> questSoulQuestionsByQuestionId(@Param("questionId")Long questionId);

    @Select("SELECT id,myoption AS `option`,fraction,question_id AS questionId FROM tb_option WHERE question_id = #{id} ")
    List<Option> questOptions(@Param("id") Long id);

    /**
     * 根据questionId 和 optionId 来查询分数
     * @param questionId
     * @param optionId
     * @return
     */
    @Select("select op.fraction from tb_bquestion tb INNER JOIN tb_option op \n" +
            "on tb.id = op.question_id where tb.id = #{questionId} and op.id=#{optionId}")
    Integer totalScoreByQuestionIdAndOptionId(@Param("questionId") Long questionId,@Param("optionId") Long optionId);
}
